package com.example.websocket.chatroom;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @Author Administrator
 * @Date 2023 11 17 10 49
 **/
@Controller
@RequestMapping("/api")
public class WebsocketController {

    /**
     * 生成一个用户，并跳转到页面
     * @param name
     * @param model
     * @return
     */
    @RequestMapping("/websocket/{name}")
    public String webSocket(@PathVariable String name, Model model){
        try{
            model.addAttribute("username",name);
            return "chatroom";
        }
        catch (Exception e){
            return "error";
        }
    }

}

